﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using System.Linq.Expressions;

namespace Data
{
    /// <summary>
    /// 数据操作规范
    /// </summary>
    public interface IRepository
    {
        /// <summary>
        ///  更新实体
        /// </summary>
        /// <param name="entity"></param>
        void Update(EntityBase entity);
        /// <summary>
        /// [批量]更新实体
        /// </summary>
        /// <param name="list"></param>
        void Update(IList<EntityBase> list);

        /// <summary>
        ///  插入实体
        /// </summary>
        void Insert(EntityBase entity);

        /// <summary>
        ///  [批量]插入实体
        /// </summary>
        void Insert(IList<EntityBase> list);

        /// <summary>
        /// 插入记录并返回刚刚立即插入的状态视图
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TEntity InsertGetIDENTITY<TEntity>(EntityBase entity) where TEntity : EntityBase;

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Delete(EntityBase entity);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        void Delete(IList<EntityBase> list);


        /// <summary>
        /// 返回默认结果集
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> GetModel<TEntity>() where TEntity : EntityBase;

        /// <summary>
        /// 根据条件返回结果结果集
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> GetModel<TEntity>(Expression<Func<EntityBase, bool>> predicate) where TEntity : EntityBase;

        /// <summary>
        /// 通过主键，得到实体
        /// 始终从数据库中获取数据
        /// </summary>
        /// <param name="keyValues"></param>
        /// <returns></returns>
        TEntity Find<TEntity>(params object[] keyValues) where TEntity : EntityBase;

    }
}
